package org.jeecg.modules.knowledgecomment.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.comment.vo.CommentPublish;
import org.jeecg.modules.knowledgecomment.entity.KnowledgeComment;
import org.jeecg.modules.knowledgecomment.mapper.KnowledgeCommentMapper;
import org.jeecg.modules.knowledgecomment.service.IKnowledgeCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: knowledge_comment
 * @Author: jeecg-boot
 * @Date:   2020-12-30
 * @Version: V1.0
 */
@Service
public class KnowledgeCommentServiceImpl extends ServiceImpl<KnowledgeCommentMapper, KnowledgeComment> implements IKnowledgeCommentService {

    @Autowired
    private KnowledgeCommentMapper knowledgeCommentMapper;
    @Override
    public IPage<CommentPublish> queryListPublishPage(Page<CommentPublish> page, String articleId) {
        List<CommentPublish> list = knowledgeCommentMapper.queryPublishListPage(page,articleId).stream()
                .sorted(Comparator.comparing(CommentPublish::getCreateTime).reversed()).collect(Collectors.toList());
        return page.setRecords(list);
    }
}
